/**
 *学生基本信息管理模块
 **/
$(function () {
    //学生评教列表
    $('#manager-teachereview').datagrid({
        url: Think.APP + "TeachReview/index&cmd=ReviewInfo", //数据源
        fit: true, //自适应
        striped: true,
        fitColumns: true,
        toolbar: '#teachereview-toolbar',
        border: false, //取消边框
        pagination: true, //分页开启
        pageSize: 50,
        rownumbers: true,
        columns: [[
            { title: 'ID', field: 'review_id', checkbox: true },
            { field: 'cu_name', title: '课程', width: 100, align: 'center' },
            { field: 'cu_id', hidden: true, width: 100, align: 'center' },
            { field: 'mc_id', hidden: true, width: 100, align: 'center' },
            {
                field: 'it_id', title: '教师', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value <= 0) {
                        return "无";
                    }
                    return Store().converter(app_data.info.teacher("STORE"), value);
                }
            },
            {
                field: 'ico_id', title: '学部', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value <= 0) {
                        return "无";
                    }
                    return Store().converter(app_data.info.college("STORE"), value);
                }
            },
            {
                field: 'id_id', title: '专业', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value <= 0) {
                        return "无";
                    }
                    return Store().converter(app_data.info.discipline("STORE"), value);
                }
            },
            {
                field: 'icl_id', title: '班级', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value <= 0) {
                        return "无";
                    }
                    return Store().converter(app_data.info.classinfo("STORE"), value);
                }
            },
            { field: 'review_create_time', title: '开始日期', width: 100, align: 'center' },
            { field: 'review_end_time', title: '结束日期', width: 100, align: 'center' },
        ]],
        onClickRow: function (rowIndex, rowData) {//单击事件
            $('#manager-teachereview').datagrid("clearChecked"); //取消所有行的选中
            $('#manager-teachereview').datagrid("selectRow", rowIndex);  //选中当前行
            $('#teachereview_studentinfo').datagrid({ url: Think.APP + "TeachReview/teachReviewStudentInfo&review_id=" + rowData.review_id });  //重新加载数据
        }
    });


    //学生评教列表
    $('#manager-reviewlable').datagrid({
        url: Think.APP + "TeachReview/index&cmd=ReviewLable", //数据源
        fit: true, //自适应
        striped: true,
        fitColumns: true,
        toolbar: '#reviewlable-toolbar',
        border: false, //取消边框
        pagination: true, //分页开启
        pageSize: 50,
        rownumbers: true,
        columns: [[
            { title: 'ID', field: 'lable_id', checkbox: true },
            { field: 'lable_name', title: '标签名称', width: 100, align: 'center' },
            {
                field: 'lable_level', title: '标签级别', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value == 1) {
                        return "好评";
                    } else if (value == 2) {
                        return "中评";
                    } else if (value == 3) {
                        return "差评";
                    }
                }
            }
        ]]
    });


    /**
     * 评教对应-学生列表
     */
    $('#teachereview_studentinfo').datagrid({
        fit: true, //自适应
        striped: true,
        fitColumns: true,
        toolbar: '#teachereview-studentinfo-toolbar',
        border: false, //取消边框
        pagination: true, //分页开启
        pageSize: 50,
        rownumbers: true,
        columns: [[
            { title: 'ID', field: 'review_id', checkbox: true },
            { field: 'is_id', title: '学号', width: 100, align: 'center' },
            { field: 'is_name', title: '姓名', width: 100, align: 'center' },
            {
                field: 'review_status', title: '是否评教', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value == 9) {
                        return "<font style='color:red'>已评价<font>";
                    } else {
                        return "未评价";
                    }
                }
            }
        ]]
    });

    /**
     * 教师评价信息
     */
    $('#manager-teachreviewinfo').datagrid({
        url: Think.APP + "TeachReview/index&cmd=ReviewTeacherInfo&is_me=all", //数据源
        fit: true, //自适应
        striped: true,
        fitColumns: true,
        toolbar: '#teachreviewinfo-toolbar',
        border: false, //取消边框
        pagination: true, //分页开启
        pageSize: 50,
        rownumbers: true,
        columns: [[
            { title: 'ID', field: 'rt_id', checkbox: true },
            {
                field: 'it_id', title: '教师', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value <= 0) {
                        return "无";
                    }
                    return Store().converter(app_data.info.teacher("STORE"), value);
                }
            },
            { field: 'cu_name', title: '课程', width: 100, align: 'center' },
            {
                field: 'ico_id', title: '学部', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value <= 0) {
                        return "无";
                    }
                    return Store().converter(app_data.info.college("STORE"), value);
                }
            },
            {
                field: 'id_id', title: '专业', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value <= 0) {
                        return "无";
                    }
                    var store = app_data.info.discipline("LIST");
                    for(var key in store){
                        if(store[key].id_id==value){
                           return  store[key].id_name_year;
                        }
                    }
                    return "";
                }
            },
            {
                field: 'icl_id', title: '班级', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value <= 0) {
                        return "无";
                    }
                    return Store().converter(app_data.info.classinfo("STORE"), value);
                }
            },
            { field: 'reivew_origin_count', title: '应评总人数', width: 100, align: 'center' },
            { field: 'review_count', title: '已评总人数', width: 100, align: 'center' },
            { field: 'review_sum_grade', title: '总分数', width: 100, align: 'center' },
            { field: 'review_grade', title: '平均分数', width: 100, align: 'center' }
        ]]
    });

    /**
     * 我的-教师评价信息
     */
    $('#manager-myteachreviewinfo').datagrid({
        url: Think.APP + "TeachReview/index&cmd=ReviewTeacherInfo&is_me=my", //数据源
        fit: true, //自适应
        striped: true,
        fitColumns: true,
        toolbar: '#myteachreviewinfo-toolbar',
        border: false, //取消边框
        pagination: true, //分页开启
        pageSize: 50,
        rownumbers: true,
        columns: [[
            { title: 'ID', field: 'rt_id', checkbox: true },
            {
                field: 'it_id', title: '教师', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value <= 0) {
                        return "无";
                    }
                    return Store().converter(app_data.info.teacher("STORE"), value);
                }
            },
            { field: 'cu_name', title: '课程', width: 100, align: 'center' },
            {
                field: 'ico_id', title: '学部', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value <= 0) {
                        return "无";
                    }
                    return Store().converter(app_data.info.college("STORE"), value);
                }
            },
            {
                field: 'id_id', title: '专业', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value <= 0) {
                        return "无";
                    }
                    var store = app_data.info.discipline("LIST");
                    for(var key in store){
                        if(store[key].id_id==value){
                           return  store[key].id_name_year;
                        }
                    }
                    return "";
                }
            },
            {
                field: 'icl_id', title: '班级', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value <= 0) {
                        return "无";
                    }
                    return Store().converter(app_data.info.classinfo("STORE"), value);
                }
            },
            { field: 'reivew_origin_count', title: '应评总人数', width: 100, align: 'center' },
            { field: 'review_grade', title: '已评总人数', width: 100, align: 'center' },
            { field: 'review_sum_grade', title: '总分数', width: 100, align: 'center' },
            { field: 'review_grade', title: '平均分数', width: 100, align: 'center' }
        ]]
    });



    teachereview_toolbar = {
        addReviewLable: function () {  //添加
            var url = Think.APP + "TeachReview/insert&cmd=ReviewLable";
            //打开弹出窗口
            Xwindow.baseDialogInit("#manager-reviewlable", "#add-reviewlable-form", "添加评教标签", url);
        },
        searchReview: function (value, name) {
            $('#manager-teachereview').datagrid("load", {
                "cu_name": value
            });
        },
        searchStudent: function (value, name) {
            $('#teachereview_studentinfo').datagrid("load", {
                "is_id": value
            });
        },
        searchTeachReview: function (value, name) {
            $('#manager-teachreviewinfo').datagrid("load", {
                "cu_name": value
            });
        },
        searchMyTeachReview: function (value, name) {
            $('#manager-myteachreviewinfo').datagrid("load", {
                "cu_name": value,
            });
        },
        deleteReviewLable: function () {
            var url = Think.APP + "TeachReview/del&cmd=ReviewLable";
            Xwindow.baseDelete("#manager-reviewlable", url, "lable_id");
        },
        deleteTeachReviewInfo: function () {
            var url = Think.APP + "TeachReview/del&cmd=ReviewTeacherInfo";
            Xwindow.baseDelete("#manager-teachreviewinfo", url, "rt_id");
        },
        //更新教师评价信息
        updateteacherreview: function () {
            var url = Think.APP + "TeachReview/updateteacherreview";
            $.messager.confirm('提示', '确定更新教师评价信息?', function (r) {
                if (r) {
                    $.ajax({
                        url: url,
                        dataType: "json",
                        type: 'post',
                        success: function (data) {
                            if (data.success == true) {
                                $("#manager-teachreviewinfo").datagrid("reload");  //重新加载数据
                            } else {
                                $.messager.alert('提示', '更新失败');
                            }
                        }
                    })
                }
            });
        }
    };

});